def input_password():
    """输入函数"""
    pwd = input("请输入密码: ")
    # 判断密码长度
    if len(pwd) < 8:
        # 实例化异常类对象，抛出密码长度不足8位的异常
        ex = Exception("输入密码长度不足8位")
        raise ex  # 主动抛出异常
    else:
        return pwd

if __name__ == '__main__':
    # 捕获异常
    try:
        print(input_password())
    except Exception as e:
        print(e)